package cn.ctodb.mall.goods.freemarker.macro;

import cn.ctodb.mall.goods.service.CategoryService;
import freemarker.core.Environment;
import freemarker.template.*;
import org.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * Created by cc on 2017/4/6.
 */
@Component
public class CategoryDirective implements TemplateDirectiveModel {

    @Autowired
    DefaultObjectWrapper defaultObjectWrapper;
    @Autowired
    CategoryService categoryService;

    @Override
    public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
        List<Map<String, Object>> navbar = categoryService.getNavbar();
        env.setVariable("navbar", defaultObjectWrapper.wrap(navbar));
        body.render(env.getOut());
    }

}
